package main

import (
	"encoding/json"
	"fmt"
	"log"
	"strings"
)

func main() {

	jsonStream := `[
		{"Name": "Ed", "Text": "Knock knock."},
		{"Name": "Sam", "Text": "Who's there?"},
		{"Name": "Ed", "Text": "Go fmt."},
		{"Name": "Sam", "Text": "Go fmt who?"},
		{"Name": "Ed", "Text": "Go fmt yourself!"}
	]`

	dec := json.NewDecoder(strings.NewReader(jsonStream))
	token, err := dec.Token()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%T: %v\n", token, token)
	for dec.More() {
		var m Message
		// decode an array value (Message)
		err := dec.Decode(&m)
		if err != nil {
			log.Fatal(err)
		}
		//json.Delim: [
		//Ed: Knock knock.
		//Sam: Who's there?
		//Ed: Go fmt.
		//Sam: Go fmt who?
		//Ed: Go fmt yourself!
		//json.Delim: ]
		fmt.Printf("%v: %v\n", m.Name, m.Text)
	}
	// read closing bracket
	t, err := dec.Token()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%T: %v\n", t, t)
}

type Message struct {
	Name, Text string
}
